home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CUCD / Programming / OUI / rcs / gadgetlist.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  6.7 KB  |  342 lines

  1. head    1.4;
  2. access;
  3. symbols;
  4. locks
  5.     dlorre:1.4; strict;
  6. comment    @// @;
  7.  
  8.  
  9. 1.4
  10. date    97.09.17.08.16.09;    author dlorre;    state Exp;
  11. branches;
  12. next    1.3;
  13.  
  14. 1.3
  15. date    97.07.14.04.20.08;    author dlorre;    state Exp;
  16. branches;
  17. next    1.2;
  18.  
  19. 1.2
  20. date    96.08.28.20.03.22;    author dlorre;    state Exp;
  21. branches;
  22. next    1.1;
  23.  
  24. 1.1
  25. date    96.08.22.02.05.10;    author dlorre;    state Exp;
  26. branches;
  27. next    ;
  28.  
  29.  
  30. desc
  31. @Oui.lib -- Object User Interface
  32. Projet créé en 1994
  33. Auteur: Dominique Lorre
  34. @
  35.  
  36.  
  37. 1.4
  38. log
  39. @*** empty log message ***
  40. @
  41. text
  42. @// $Id: gadgetlist.cc 1.3 1997/07/14 04:20:08 dlorre Exp dlorre $
  43. #define INTUI_V36_NAMES_ONLY
  44.  
  45. #include <exec/types.h>
  46. #include <exec/memory.h>
  47.  
  48. #include <graphics/gfxbase.h>
  49. #include <libraries/gadtools.h>
  50.  
  51. #include <devices/timer.h>
  52.  
  53. #include <string.h>
  54. #include <stdio.h>
  55. #include <ctype.h>
  56. #include <mydebug.h>
  57.  
  58. #include <proto/exec.h>
  59. #include <proto/dos.h>
  60. #include <proto/graphics.h>
  61. #include <proto/intuition.h>
  62. #include <proto/gadtools.h>
  63.  
  64. #include "screen.h"
  65. #include "window.h"
  66. #include "gadgetlist.h"
  67. #include "gadgets/gadget.h"
  68.  
  69. static struct EasyStruct GadgetListES = {
  70.     sizeof(struct EasyStruct),
  71.     0,
  72.     (UBYTE *)"GadgetList Corrupted",
  73.     (UBYTE *)"A window is in closing process.\n This window use %ld gadgets but %ld are declared.\nSorry, system will crash",
  74.     (UBYTE *)"Ok"
  75. } ;
  76.  
  77.  
  78. // ========================================================================
  79. // ==========================  GADGETLIST CLASS ===========================
  80. // ========================================================================
  81.  
  82. gadgetlist::gadgetlist(window *w,
  83.                       WORD gmax) :  rectangle(0, 0, 0, 0),
  84.                                     count(0),
  85.                                     max(gmax),
  86.                                     win(w),
  87.                                     bfont(NULL),
  88.                                     initok(FALSE),
  89.                                     glist(NULL)
  90. {
  91.  
  92.     if (gtab = new gadget *[max]) {
  93.         if (ng = new NewGadget) {
  94.             if (it = new IntuiText) {
  95.                 gpen = win->ws->drawinfo->dri_Pens[TEXTPEN] ;     // Front pen
  96.                 ng->ng_VisualInfo = win->ws->vi ;
  97.                 setfont((TTextAttr *)win->ws->scr->Font) ;
  98.                 if (bfont) {
  99.                     ng->ng_GadgetText = NULL ;
  100.                     ng->ng_Width = width ;
  101.                     ng->ng_Height = height ;
  102.                     ng->ng_LeftEdge = left ;
  103.                     ng->ng_TopEdge = top ;
  104.  
  105.                     if (gad = (Gadget *)CreateContext(&glist)) {
  106.                         wp = win->win ;
  107.                         initok = TRUE ;
  108.                     }
  109.                 }
  110.  
  111.             }
  112.         }
  113.  
  114.     }
  115. }
  116.  
  117. gadgetlist::~gadgetlist() {
  118.  
  119.     if (max < count) {
  120.         EasyRequest(NULL, &GadgetListES, NULL, count, max) ;
  121.     }
  122.     if (bfont) CloseFont(bfont) ;
  123.     if (initok) FreeGadgets(glist) ;
  124.     if (gtab) {
  125.     int i ;
  126.         for (i=0; i<count; i++) {
  127. // uncomment the following if your window crashes on exit...
  128. //            D(bug("freeing gtab[%ld] %lx\n", i, gtab[i])) ;
  129.             if (gtab[i]) delete gtab[i] ;
  130.         }
  131.         delete gtab ;
  132.     }
  133.     if (ng) delete ng ;
  134.     if (it) delete it ;
  135. }
  136.  
  137. void gadgetlist::processgadget(LONG id, unsigned long classe, unsigned short code)
  138. {
  139.     gtab[id]->action(classe, code) ;
  140. }
  141.  
  142. void gadgetlist::addgadgets()
  143. {
  144.     if (gad) {
  145.         AddGList(wp, glist, -1, -1, NULL);
  146.         RefreshGList(glist, wp, NULL, -1);
  147.         GT_RefreshWindow(wp, NULL) ;
  148.         win->hasgadgets = TRUE ;
  149.     }
  150.     else
  151.         win->initok = FALSE ;
  152. }
  153.  
  154. void gadgetlist::updategadgets()
  155. {
  156. int i ;
  157.     wp = win->win ;
  158.     for (i=0; i<count; i++)
  159.         if (gtab[i])
  160.             gtab[i]->w = wp ;
  161.     GT_RefreshWindow(wp, NULL) ;
  162.     win->hasgadgets = TRUE ;
  163. }
  164.  
  165. void gadgetlist::setfont(TTextAttr *tta)
  166. {
  167.     CopyMem(tta, &PlainAttr, sizeof(TTextAttr)) ;
  168.     BoldAttr = PlainAttr ;
  169.     BoldAttr.tta_Style |= FSF_BOLD ;
  170.     fontheight = PlainAttr.tta_YSize ;
  171.     if (bfont) CloseFont(bfont) ;
  172.     bfont = OpenFont((TextAttr *)&BoldAttr) ;
  173.     setdefault(FALSE) ;
  174. }
  175.  
  176. void gadgetlist::setdefault(BOOL bolden)
  177. {
  178.     it->ITextFont = ng->ng_TextAttr =
  179.             bolden ?(TextAttr *)&BoldAttr: (TextAttr *)&PlainAttr ;
  180. }
  181.  
  182. long gadgetlist::ltext(const char *s)
  183. {
  184.     it->IText = (UBYTE *)s ;
  185.     return IntuiTextLength(it) ;
  186. }
  187.  
  188. long gadgetlist::lmax(const char **ms)
  189. {
  190. long max=0, l ;
  191.  
  192.     while (*ms)
  193.         if ((l = ltext(*ms++)) > max) max = l ;
  194.  
  195.     return max ;
  196. }
  197.  
  198. long gadgetlist::lmax(const char *s, ...)
  199. {
  200. const char **ms = &s ;
  201.     return lmax(ms) ;
  202. }
  203.  
  204.  
  205. void gadgetlist::selectgadget(LONG id, BOOL shifted)
  206. {
  207.     if (id < count) gtab[id]->keystroke(shifted) ;
  208. }
  209.  
  210. void gadgetlist::parsegadgets(USHORT code)
  211. {
  212. int     i ;
  213. BOOL    shifted ;
  214.  
  215.     if (code > 0x20) {
  216.         shifted = BOOL(isupper(code)) ;
  217.         code = tolower(code) ;
  218.     }
  219.     else
  220.         shifted = FALSE ;
  221.  
  222.     for (i=0; i<count; i++) {
  223.         if (gtab[i]->key == code) {
  224.             gtab[i]->keystroke(shifted) ;
  225.         }
  226.     }
  227. }
  228.  
  229. gadget *gadgetlist::getgadget(LONG id)
  230. {
  231.     return gtab[id] ;
  232. }
  233. @
  234.  
  235.  
  236. 1.3
  237. log
  238. @*** empty log message ***
  239. @
  240. text
  241. @d1 1
  242. a1 1
  243. // $Id$
  244. d14 1
  245. d175 2
  246. a176 2
  247.         shifted = BOOL(!(code & 0x20)) ;
  248.         code |= 0x20 ;
  249. d182 1
  250. a182 1
  251.         if (gtab[i]->key == code)
  252. d184 1
  253. @
  254.  
  255.  
  256. 1.2
  257. log
  258. @*** empty log message ***
  259. @
  260. text
  261. @d1 1
  262. d14 1
  263. d16 5
  264. a20 12
  265. #include <cxxproto/exec.h>
  266. #include <cxxproto/dos.h>
  267. #include <cxxproto/graphics.h>
  268. #include <cxxproto/intuition.h>
  269.  
  270. extern "C" {
  271. extern struct Library *GadToolsBase ;
  272. struct Gadget *CreateContext( struct Gadget **glistptr );
  273. void FreeGadgets( struct Gadget *gad );
  274. void GT_RefreshWindow( struct Window *win, struct Requester *req );
  275. #include <pragmas/gadtools_pragmas.h>
  276. }
  277. d30 3
  278. a32 3
  279.     "GadgetList Corrupted",
  280.     "A window is in closing process.\n This window use %ld gadgets but %ld are declared.\nSorry, system will crash",
  281.     "Ok"
  282. d45 26
  283. a70 16
  284.                                     bfont(NULL)
  285. {
  286.     gpen = win->ws->drawinfo->dri_Pens[TEXTPEN] ;     // Front pen
  287.     max = gmax ;
  288.     gtab = new gadget *[max] ;
  289.     ng = new NewGadget ;
  290.     it = new IntuiText ;
  291.  
  292.     ng->ng_VisualInfo = win->ws->vi ;
  293.     setfont((TTextAttr *)win->ws->screen->Font) ;
  294.  
  295.     ng->ng_GadgetText = NULL ;
  296.     ng->ng_Width = width ;
  297.     ng->ng_Height = height ;
  298.     ng->ng_LeftEdge = left ;
  299.     ng->ng_TopEdge = top ;
  300. d72 1
  301. a72 2
  302.     gad = (struct Gadget *)CreateContext(&glist);
  303.     wp = win->win ;
  304. a75 1
  305. int i;
  306. d81 9
  307. a89 3
  308.     FreeGadgets(glist) ;
  309.     for (i=0; i<count; i++) {
  310.         delete gtab[i] ;
  311. d91 2
  312. a92 3
  313.     delete [] gtab ;
  314.     delete ng ;
  315.     delete it ;
  316. d140 1
  317. a140 1
  318. long gadgetlist::ltext(STRPTR s)
  319. d142 1
  320. a142 1
  321.     it->IText = s ;
  322. d146 1
  323. a146 1
  324. long gadgetlist::lmax(STRPTR *ms)
  325. d156 1
  326. a156 1
  327. long gadgetlist::lmax(STRPTR s, ...)
  328. d158 1
  329. a158 1
  330. STRPTR *ms = &s ;
  331. @
  332.  
  333.  
  334. 1.1
  335. log
  336. @Initial revision
  337. @
  338. text
  339. @d181 1
  340. a181 1
  341. }@
  342.